package com.lglbc.rocketmq;

import com.alibaba.cloud.stream.binder.rocketmq.constant.RocketMQConst;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.common.message.MessageConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Author 乐哥聊编程
 * @Doc 关注公众号"乐哥聊编程"获取文档和源码
 * @Date 2023/6/23
 * @Description
 */
@RestController
public class TestController {
    @Autowired
    private StreamBridge streamBridge;
    @RequestMapping("sendSqlMsg")
    public String sendOrderMsg() {
        MessageBuilder builder = MessageBuilder.withPayload("Hello sql msg no consumer");
        builder.setHeader(Constant.colorHeaderKey, "red1")
                .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON);
        Message<String> msg = builder.build();
        System.out.println("send Msg:" + msg.toString());
        streamBridge.send("producer-out-0", msg);

        builder = MessageBuilder.withPayload("Hello sql msg has consumer");
        builder.setHeader(Constant.colorHeaderKey, "red1")
                .setHeader(Constant.priceHeaderKey,"5")
                .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON);
        msg = builder.build();
        System.out.println("send Msg:" + msg.toString());
        streamBridge.send("producer-out-0", msg);

        builder = MessageBuilder.withPayload("Hello tag msg has consumer");
        builder.setHeader(MessageConst.PROPERTY_TAGS, "tag1")
                .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON);
        msg = builder.build();
        System.out.println("send Msg:" + msg.toString());
        streamBridge.send("producer-out-0", msg);


        builder = MessageBuilder.withPayload("Hello tag msg no consumer");
        builder.setHeader(MessageConst.PROPERTY_TAGS, "tag5")
                .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON);
        msg = builder.build();
        System.out.println("send Msg:" + msg.toString());
        streamBridge.send("producer-out-0", msg);
        return "success";
    }
}
